
function openAddrAdd() {
    $.modal.open("添加地址",ctx+"user/userAddress/add",365,450,'');
}
function editAddr(id) {
    $.modal.open("编辑地址",ctx+"user/userAddress/edit/"+id,365,450,'');
}
function convertAddr(obj) {
    return obj.receiveAddr + "\n(" + obj.receiveUser + "收)\n电话-" + obj.receiveTel;
}

function goodsClick(goodsId) {
    location.href = ctx + "index/findGoodsById/" + goodsId;
}

function goodsOnclick(goodsId) {
    return "goodsClick(" + goodsId + ")";
}

function goodsClickHref(goodsId) {
    return ctx + "index/findGoodsById/" + goodsId;
}

function preferAdd(dom, goodsId) {
    $.ajax({
        url: ctx + "user/userGoodsPrefer/add",
        type: "post",
        data: {goodsId: goodsId},
        dataType:"json",
        success: function (data) {
            if (data.code == web_status.NOT_LOGIN) {
                location.href = ctx + "login";
                return
            }
            if (data.code == web_status.SUCCESS) {
                $(dom).addClass("cancel");
                $(dom).find("span").html("取消收藏");
                $(dom).attr("onclick","preferCancel(this,"+goodsId+")");
            }
        }
    });
}

function preferCancel(dom, goodsId,callback) {
    $.ajax({
        url: ctx + "user/userGoodsPrefer/remove",
        type: "post",
        data: {goodsId: goodsId},
        dataType:"json",
        success: function (data) {
            if (data.code == web_status.NOT_LOGIN) {
                location.href = ctx + "login";
                return
            }
            if(typeof callback == "function"){
                callback(data);
            }
            if (data.code == web_status.SUCCESS) {
                $(dom).removeClass("cancel");
                $(dom).find("span").html("收藏");
                $(dom).attr("onclick","preferAdd(this,"+goodsId+")");
            }
        }
    });
}
function cartAddNum(dom, num) {
    if ($('#overall_cart').length == 0) {
        //当没有显示购物车时，弹提示
        showAlert("加入购物车成功！");
        return;
    }
    var $add_x = $(dom).offset().top;
    var $add_y = $(dom).offset().left;
    var $to_x = $('#overall_cart').offset().top-35;
    var $to_y = $('#overall_cart').offset().left+25;
    $(".add_jump").css({'left': $add_y + 80, 'top': $add_x + 10, 'display': 'block','background':'#c10000','width':'15px','height':'15px','position':'absolute','border-radius':'50%','z-index':'22'});
    $(".add_jump").stop().animate({
        'left': $to_y + 7,
        'top': $to_x + 7
    }, "fast", function () {
        $(".add_jump").fadeOut('fast', function () {
            $("#overall_cart span").html(num);
        });
    });
}

function addCartClick(dom, goodsId, goodsNum) {
    $.ajax({
        url: ctx + "user/userCart/add",
        type: "post",
        data: {
            "goodsId": goodsId,
            "goodsNum": goodsNum
        },
        dataType: "json",
        success: function (data) {
            if (data.code == web_status.NOT_LOGIN) {
                location.href = ctx + "login";
            }
            if (data.code == web_status.SUCCESS) {
                cartAddNum(dom, data.data);
            }
        }
    });
}
function showAlert(msg, timeout, callback) {
    if ($.common.isEmpty(timeout)) {
        timeout = 2000;
    }
    var htmlStr = '<div class="popup_con">' +
        '<div class="popup">' +
        '     <p>' + msg + '</p>' +
        '</div>' +
        '<div class="mask"></div>' +
        '</div>';
    $("body").append(htmlStr);
    $('.popup_con').fadeIn('fast', function () {
        setTimeout(function () {
            $('.popup_con').fadeOut('fast', function () {
                $(".popup_con").remove();
                if (typeof callback == "function") {
                    callback();
                }
            });
        }, timeout);
    });
}
function convertAddr(obj) {
    return obj.receiveAddr + "\n(" + obj.receiveUser + "收)\n电话-" + obj.receiveTel;
}

function convertStatus(status) {
    var obj = {"1": "配送中", "2": "已收货", "3": "已评价", "4": "待配送", "5": "已取消","6":"退货退款中","7":"已退货退款"};
    return obj[status];
}